﻿import re
import logging

from django.shortcuts import render_to_response
from google.appengine.api import users


# ##################################################################################################
def render(template, payload):
    '''render the template with payload'''
    return render_to_response(template, payload)

def getAllUsers():
    '''get all the users order by the last access'''
    return models.User.all().order('-last_update')

def getUser(email="anonymous@gmail.com"):
    '''get all the current user, if not exist, return anonymous'''
    user = users.get_current_user()
    if not user:
        user = users.User(email)
    return user

def getLoginAndUrl(request):
    '''get toggled login and logout label and the url'''
    if users.get_current_user():
        url = users.create_logout_url(request.get_full_path())
        url_linktext = '注销'
    else:
        url = users.create_login_url(request.get_full_path())
        url_linktext = '登陆'
    return url_linktext, url
    
